from flask import Flask, render_template
import json
from werkzeug.exceptions import HTTPException

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/hello')
def hello():
    a = 1/0
    return "ok"

# @app.errorhandler(werkzeug.exceptions.HTTPException)
# def handle_bad_request(e):
    # return 'error', 200

# app.register_error_handler(404, handle_bad_request)
# app.register_error_handler(500, handle_bad_request)

# @app.errorhandler(HTTPException)
# def handle_exception(e):
#     response = e.get_response()
#     response.data = json.dumps({
#         "code": e.code,
#         "name": e.name,
#         "description": e.description
#     })
#     response.content_type = 'application/json'
#     return response

@app.errorhandler(Exception)
def handle_exception(e):
    if isinstance(e, HTTPException):
        return e

    response = e.get_response()
    response.data = json.dumps({
        "error": e.message
    })
    response.content_type = 'application/json'
    return response 

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8000, debug=True)